/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * vistaTipoDeMaquina.java
 *
 * Created on 7/04/2011, 05:10:55 AM
 */

package jcpcotizaciones.vista;

import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import jcpcotizaciones.Control.ControlProveedor;
import jcpcotizaciones.Control.ControlTipoDeMaquina;
import jcpcotizaciones.Modelo.Proveedor;
import jcpcotizaciones.Modelo.TipoDeMaquina;

/**
 *
 * @author David
 */
public class vistaTipoDeMaquina extends javax.swing.JFrame {

    /** Creates new form vistaTipoDeMaquina */
    public vistaTipoDeMaquina() {
        initComponents();
       listarProveedor();
        listarTipoDeMaquina();
    }
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    DefaultTableModel dtm = new DefaultTableModel();

       public void listarTipoDeMaquina(){
        TipoDeMaquina tipo = new TipoDeMaquina();
        try {
            dtm.setNumRows(0);
            ControlTipoDeMaquina.listarTipoDeMaquina();
            Iterator it = ControlTipoDeMaquina.getTipoMaquina().iterator();
                while (it.hasNext()) {
                    tipo = (TipoDeMaquina) it.next();
                    String[] fila = {tipo.getCodigoMaquina(), tipo.getNombre(), tipo.getTamanoMaximo(), tipo.getTamanoMinimo(), Double.toString(tipo.getValorMillar()),Double.toString(tipo.getValorMillarNumeracion()),Double.toString(tipo.getValorPlancha()), tipo.getProveedor().getNombre()};
                    dtm.addRow(fila);
                }
            DecimalFormat formateador = new DecimalFormat("000");
            if(tipo.getCodigoMaquina()==null){
                tx_codigo.setText(formateador.format(1));
            }else{
                int contador_tipo =Integer.parseInt(tipo.getCodigoMaquina());
                contador_tipo+=1;
                tx_codigo.setText(formateador.format(contador_tipo));
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void limpiar(){
       
        tx_nombre.setText("");
        tx_tamMaximo.setText("");
        tx_tamMinimo.setText("");
        tx_vrMillar.setText("");
        tx_vrPlancha.setText("");
        tx_millarNum.setText("");
        cb_proveedor.setSelectedIndex(0);
        bt_modificar.setEnabled(false);
        bt_eliminar.setEnabled(false);
        bt_agregar.setEnabled(true);

    }


   public void listarProveedor(){
       try {
            Proveedor pro = new Proveedor();
            dcbm.removeAllElements();
            ControlProveedor.listarProveedor();
            Iterator it = ControlProveedor.getProveedor().iterator();
            while (it.hasNext()) {
                pro = (Proveedor) it.next();
                dcbm.addElement(pro.getCodigoProvee() + " - " + pro.getNombre());
            }
            cb_proveedor.setModel(dcbm);
        } catch (SQLException ex) {
            Logger.getLogger(vistaTipoDeMaquina.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaTipoDeMaquina.class.getName()).log(Level.SEVERE, null, ex);
        }
   }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogo = new javax.swing.JDialog();
        bt_aceptarEliminar = new javax.swing.JButton();
        bt_cancelarEliminar = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        autoCompleteDecorator1 = new org.jdesktop.swingx.autocomplete.AutoCompleteDecorator();
        pisoTipoDeMaquina = new jcMousePanel.jcMousePanel();
        jcMousePanel2 = new jcMousePanel.jcMousePanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        tx_codigo = new javax.swing.JTextField();
        tx_nombre = new javax.swing.JTextField();
        tx_tamMaximo = new javax.swing.JTextField();
        tx_tamMinimo = new javax.swing.JTextField();
        tx_vrMillar = new javax.swing.JTextField();
        tx_vrPlancha = new javax.swing.JTextField();
        cb_proveedor = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        tx_millarNum = new javax.swing.JTextField();
        jcMousePanel3 = new jcMousePanel.jcMousePanel();
        bt_agregar = new javax.swing.JButton();
        bt_modificar = new javax.swing.JButton();
        bt_eliminar = new javax.swing.JButton();
        bt_limpiar = new javax.swing.JButton();
        jcMousePanel4 = new jcMousePanel.jcMousePanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaMaquinas = new javax.swing.JTable(dtm);
        bt_buscar = new javax.swing.JButton();
        tx_buscar = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jcMousePanel1 = new jcMousePanel.jcMousePanel();

        dialogo.setName("dialogo"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jcpcotizaciones.JCPCOTIZACIONESApp.class).getContext().getResourceMap(vistaTipoDeMaquina.class);
        bt_aceptarEliminar.setText(resourceMap.getString("bt_aceptarEliminar.text")); // NOI18N
        bt_aceptarEliminar.setName("bt_aceptarEliminar"); // NOI18N
        bt_aceptarEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_aceptarEliminarActionPerformed(evt);
            }
        });

        bt_cancelarEliminar.setText(resourceMap.getString("bt_cancelarEliminar.text")); // NOI18N
        bt_cancelarEliminar.setName("bt_cancelarEliminar"); // NOI18N
        bt_cancelarEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelarEliminarActionPerformed(evt);
            }
        });

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout dialogoLayout = new javax.swing.GroupLayout(dialogo.getContentPane());
        dialogo.getContentPane().setLayout(dialogoLayout);
        dialogoLayout.setHorizontalGroup(
            dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dialogoLayout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addGroup(dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(dialogoLayout.createSequentialGroup()
                        .addGap(75, 75, 75)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(34, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dialogoLayout.createSequentialGroup()
                        .addGap(116, 116, 116)
                        .addGroup(dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(bt_aceptarEliminar))
                        .addGap(29, 29, 29)
                        .addComponent(bt_cancelarEliminar)
                        .addContainerGap())))
        );
        dialogoLayout.setVerticalGroup(
            dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dialogoLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addGroup(dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_aceptarEliminar)
                    .addComponent(bt_cancelarEliminar))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        pisoTipoDeMaquina.setIcon(resourceMap.getIcon("pisoTipoDeMaquina.icon")); // NOI18N
        pisoTipoDeMaquina.setName("pisoTipoDeMaquina"); // NOI18N

        jcMousePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel2.border.titleFont"), resourceMap.getColor("jcMousePanel2.border.titleColor"))); // NOI18N
        jcMousePanel2.setIcon(resourceMap.getIcon("jcMousePanel2.icon")); // NOI18N
        jcMousePanel2.setName("jcMousePanel2"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        tx_codigo.setFont(resourceMap.getFont("tx_codigo.font")); // NOI18N
        tx_codigo.setText(resourceMap.getString("tx_codigo.text")); // NOI18N
        tx_codigo.setEnabled(false);
        tx_codigo.setName("tx_codigo"); // NOI18N

        tx_nombre.setText(resourceMap.getString("tx_nombre.text")); // NOI18N
        tx_nombre.setName("tx_nombre"); // NOI18N

        tx_tamMaximo.setText(resourceMap.getString("tx_tamMaximo.text")); // NOI18N
        tx_tamMaximo.setName("tx_tamMaximo"); // NOI18N

        tx_tamMinimo.setText(resourceMap.getString("tx_tamMinimo.text")); // NOI18N
        tx_tamMinimo.setName("tx_tamMinimo"); // NOI18N

        tx_vrMillar.setText(resourceMap.getString("tx_vrMillar.text")); // NOI18N
        tx_vrMillar.setName("tx_vrMillar"); // NOI18N

        tx_vrPlancha.setText(resourceMap.getString("tx_vrPlancha.text")); // NOI18N
        tx_vrPlancha.setName("tx_vrPlancha"); // NOI18N
        tx_vrPlancha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tx_vrPlanchaKeyPressed(evt);
            }
        });

        cb_proveedor.setEditable(true);
        cb_proveedor.setMaximumRowCount(5);
        cb_proveedor.setName("cb_proveedor"); // NOI18N
        cb_proveedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cb_proveedorKeyPressed(evt);
            }
        });

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        tx_millarNum.setText(resourceMap.getString("tx_millarNum.text")); // NOI18N
        tx_millarNum.setName("tx_millarNum"); // NOI18N

        javax.swing.GroupLayout jcMousePanel2Layout = new javax.swing.GroupLayout(jcMousePanel2);
        jcMousePanel2.setLayout(jcMousePanel2Layout);
        jcMousePanel2Layout.setHorizontalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel2Layout.createSequentialGroup()
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tx_codigo)
                    .addComponent(tx_nombre)
                    .addComponent(tx_tamMaximo)
                    .addComponent(tx_tamMinimo, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(tx_vrMillar)
                    .addComponent(tx_millarNum)
                    .addComponent(cb_proveedor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tx_vrPlancha)))
        );
        jcMousePanel2Layout.setVerticalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel2Layout.createSequentialGroup()
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tx_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tx_tamMaximo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tx_tamMinimo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tx_vrMillar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(tx_millarNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tx_vrPlancha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cb_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)))
        );

        jcMousePanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel3.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel3.border.titleFont"), resourceMap.getColor("jcMousePanel3.border.titleColor"))); // NOI18N
        jcMousePanel3.setIcon(resourceMap.getIcon("jcMousePanel3.icon")); // NOI18N
        jcMousePanel3.setName("jcMousePanel3"); // NOI18N

        bt_agregar.setIcon(resourceMap.getIcon("bt_agregar.icon")); // NOI18N
        bt_agregar.setText(resourceMap.getString("bt_agregar.text")); // NOI18N
        bt_agregar.setName("bt_agregar"); // NOI18N
        bt_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarActionPerformed(evt);
            }
        });

        bt_modificar.setIcon(resourceMap.getIcon("bt_modificar.icon")); // NOI18N
        bt_modificar.setText(resourceMap.getString("bt_modificar.text")); // NOI18N
        bt_modificar.setEnabled(false);
        bt_modificar.setName("bt_modificar"); // NOI18N
        bt_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modificarActionPerformed(evt);
            }
        });

        bt_eliminar.setIcon(resourceMap.getIcon("bt_eliminar.icon")); // NOI18N
        bt_eliminar.setText(resourceMap.getString("bt_eliminar.text")); // NOI18N
        bt_eliminar.setEnabled(false);
        bt_eliminar.setName("bt_eliminar"); // NOI18N
        bt_eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_eliminarActionPerformed(evt);
            }
        });

        bt_limpiar.setIcon(resourceMap.getIcon("bt_limpiar.icon")); // NOI18N
        bt_limpiar.setText(resourceMap.getString("bt_limpiar.text")); // NOI18N
        bt_limpiar.setName("bt_limpiar"); // NOI18N
        bt_limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jcMousePanel3Layout = new javax.swing.GroupLayout(jcMousePanel3);
        jcMousePanel3.setLayout(jcMousePanel3Layout);
        jcMousePanel3Layout.setHorizontalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(bt_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_eliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jcMousePanel3Layout.setVerticalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel3Layout.createSequentialGroup()
                .addComponent(bt_agregar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bt_modificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bt_eliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_limpiar)
                .addContainerGap(80, Short.MAX_VALUE))
        );

        jcMousePanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel4.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel4.border.titleFont"), resourceMap.getColor("jcMousePanel4.border.titleColor"))); // NOI18N
        jcMousePanel4.setIcon(resourceMap.getIcon("jcMousePanel4.icon")); // NOI18N
        jcMousePanel4.setName("jcMousePanel4"); // NOI18N

        jScrollPane1.setAlignmentX(1.0F);
        jScrollPane1.setAlignmentY(1.0F);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        dtm.addColumn("Código");
        dtm.addColumn("Nombre");
        dtm.addColumn("Tam. Máximo");
        dtm.addColumn("Tam. Minimo");
        dtm.addColumn("Vr. Millar");
        dtm.addColumn("Vr. Millar Num.");
        dtm.addColumn("Vr. Plancha");
        dtm.addColumn("Proveedor");
        tablaMaquinas.setAutoCreateRowSorter(true);
        tablaMaquinas.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tablaMaquinas.setCellSelectionEnabled(true);
        tablaMaquinas.setEnabled(false);
        tablaMaquinas.setName("tablaMaquinas"); // NOI18N
        jScrollPane1.setViewportView(tablaMaquinas);

        javax.swing.GroupLayout jcMousePanel4Layout = new javax.swing.GroupLayout(jcMousePanel4);
        jcMousePanel4.setLayout(jcMousePanel4Layout);
        jcMousePanel4Layout.setHorizontalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
        );
        jcMousePanel4Layout.setVerticalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
        );

        bt_buscar.setIcon(resourceMap.getIcon("bt_buscar.icon")); // NOI18N
        bt_buscar.setText(resourceMap.getString("bt_buscar.text")); // NOI18N
        bt_buscar.setName("bt_buscar"); // NOI18N
        bt_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_buscarActionPerformed(evt);
            }
        });

        tx_buscar.setText(resourceMap.getString("tx_buscar.text")); // NOI18N
        tx_buscar.setName("tx_buscar"); // NOI18N
        tx_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_buscarActionPerformed(evt);
            }
        });

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jcMousePanel1.setIcon(resourceMap.getIcon("jcMousePanel1.icon")); // NOI18N
        jcMousePanel1.setName("jcMousePanel1"); // NOI18N

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 404, Short.MAX_VALUE)
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 52, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout pisoTipoDeMaquinaLayout = new javax.swing.GroupLayout(pisoTipoDeMaquina);
        pisoTipoDeMaquina.setLayout(pisoTipoDeMaquinaLayout);
        pisoTipoDeMaquinaLayout.setHorizontalGroup(
            pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                .addGroup(pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                        .addGroup(pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(tx_buscar, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(bt_buscar)
                                        .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                                            .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jcMousePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                        .addGap(197, 197, 197)
                        .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        pisoTipoDeMaquinaLayout.setVerticalGroup(
            pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pisoTipoDeMaquinaLayout.createSequentialGroup()
                .addGroup(pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pisoTipoDeMaquinaLayout.createSequentialGroup()
                        .addContainerGap(86, Short.MAX_VALUE)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tx_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_buscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pisoTipoDeMaquinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jcMousePanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(22, 22, 22))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoTipoDeMaquina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoTipoDeMaquina, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarActionPerformed
        try {
            TipoDeMaquina tipo = new TipoDeMaquina();
            tipo.setCodigoMaquina(tx_codigo.getText());
            tipo.setNombre(tx_nombre.getText());
            tipo.setTamanoMaximo(tx_tamMaximo.getText());
            tipo.setTamanoMinimo(tx_tamMinimo.getText());
            tipo.setValorMillar(Double.parseDouble(tx_vrMillar.getText()));
            tipo.setValorPlancha(Double.parseDouble(tx_vrPlancha.getText()));
            tipo.setValorMillarNumeracion(Double.parseDouble(tx_millarNum.getText()));
            StringTokenizer st = new StringTokenizer(cb_proveedor.getSelectedItem().toString(),"-");
            String cod = st.nextToken();
            tipo.setProveedor(ControlProveedor.BuscarProveedor(cod.trim()));

            if(tx_codigo.getText().trim().equals("") || tx_nombre.getText().trim().equals("") || tx_tamMaximo.getText().trim().equals("") || tx_millarNum.getText().trim().equals("") || tx_tamMinimo.getText().trim().equals("") || tx_vrMillar.getText().trim().equals("") || tx_vrPlancha.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Asegurece de llenar todos los campos.");
            }else{
                ControlTipoDeMaquina.agregarTipoDeMaquina(tipo);
                limpiar();
                listarTipoDeMaquina();
                JOptionPane.showMessageDialog(null,"Tipo de máquina guardada con exito!.");
            }           
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bt_agregarActionPerformed

    private void bt_limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limpiarActionPerformed
        limpiar();
        listarTipoDeMaquina();
        listarProveedor();
    }//GEN-LAST:event_bt_limpiarActionPerformed

    private void bt_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_modificarActionPerformed
        try {
            TipoDeMaquina tipo = new TipoDeMaquina();
            tipo.setCodigoMaquina(tx_codigo.getText());
            tipo.setNombre(tx_nombre.getText());
            tipo.setTamanoMaximo(tx_tamMaximo.getText());
            tipo.setTamanoMinimo(tx_tamMinimo.getText());
            tipo.setValorMillar(Double.parseDouble(tx_vrMillar.getText()));
            tipo.setValorMillarNumeracion(Double.parseDouble(tx_millarNum.getText()));
            tipo.setValorPlancha(Double.parseDouble(tx_vrPlancha.getText()));
            StringTokenizer st = new StringTokenizer(cb_proveedor.getSelectedItem().toString(),"-");
            String cod = st.nextToken();
            tipo.setProveedor(ControlProveedor.BuscarProveedor(cod.trim()));

            if(tx_codigo.getText().trim().equals("") || tx_nombre.getText().trim().equals("") || tx_tamMaximo.getText().trim().equals("") || tx_tamMinimo.getText().trim().equals("") || tx_vrMillar.getText().trim().equals("") || tx_vrPlancha.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Asegurece de llenar todos los campos.");
            }else{
                ControlTipoDeMaquina.ModificarTipoDeMaquina(tipo,tx_codigo.getText());
                limpiar();
                listarTipoDeMaquina();
                JOptionPane.showMessageDialog(null,"Tipo de máquina modificada con exito!");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bt_modificarActionPerformed

    private void bt_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_eliminarActionPerformed
        dialogo.setSize(350, 150);
        dialogo.setLocation(350, 300);
        dialogo.setVisible(true);
    }//GEN-LAST:event_bt_eliminarActionPerformed

    private void bt_aceptarEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_aceptarEliminarActionPerformed
        try {
            ControlTipoDeMaquina.EliminarTipoDeMaquina(tx_codigo.getText());
            limpiar();
            listarTipoDeMaquina();
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
      dialogo.setVisible(false);
      JOptionPane.showMessageDialog(null,"Tipo de Máquina eliminada con exito!");
    }//GEN-LAST:event_bt_aceptarEliminarActionPerformed

    private void bt_cancelarEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelarEliminarActionPerformed
      dialogo.setVisible(false);
    }//GEN-LAST:event_bt_cancelarEliminarActionPerformed

    private void bt_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_buscarActionPerformed
        buscar();
    }//GEN-LAST:event_bt_buscarActionPerformed

    private void tx_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_buscarActionPerformed
        buscar();
    }//GEN-LAST:event_tx_buscarActionPerformed

    private void cb_proveedorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cb_proveedorKeyPressed
        
    }//GEN-LAST:event_cb_proveedorKeyPressed

    private void tx_vrPlanchaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tx_vrPlanchaKeyPressed
       
    }//GEN-LAST:event_tx_vrPlanchaKeyPressed

    public void buscarcombo(){
        try {
            Proveedor pro = new Proveedor();
            ControlProveedor.listarlike(cb_proveedor.getSelectedItem().toString());
            Iterator it = ControlProveedor.getProveedor().iterator();
            dcbm.addElement(cb_proveedor.getSelectedItem().toString());
            while (it.hasNext()) {
                pro = (Proveedor) it.next();
                dcbm.addElement(pro.getCodigoProvee() + " - " + pro.getNombre());
            }
            cb_proveedor.setModel(dcbm);
        } catch (SQLException ex) {
            Logger.getLogger(vistaTipoDeMaquina.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaTipoDeMaquina.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

   public void buscar(){
            TipoDeMaquina tipo = new TipoDeMaquina();
        try {
            if(tx_buscar.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Por favor digite un criterio de busqueda.");
            }else{
                tipo = ControlTipoDeMaquina.BuscarTipoDeMaquina(tx_buscar.getText());
            
                if(tipo != null){
                    tx_codigo.setText(tipo.getCodigoMaquina());
                    tx_nombre.setText(tipo.getNombre());
                    tx_tamMinimo.setText(tipo.getTamanoMinimo());
                    tx_tamMaximo.setText(tipo.getTamanoMaximo());
                    tx_vrMillar.setText(Double.toString(tipo.getValorMillar()));
                    tx_millarNum.setText(Double.toString(tipo.getValorMillarNumeracion()));
                    tx_vrPlancha.setText(Double.toString(tipo.getValorPlancha()));
            try {
            int cont =0;
            int numcb=0;
            Proveedor pro = new Proveedor();
            dcbm.removeAllElements();
            ControlProveedor.listarProveedor();
            Iterator it = ControlProveedor.getProveedor().iterator();
            while (it.hasNext()) {
                pro = (Proveedor) it.next();
                dcbm.addElement(pro.getCodigoProvee() + " - " + pro.getNombre());
                if (pro.getCodigoProvee().equals(tipo.getProveedor().getCodigoProvee())){
                    numcb=cont;
                }
                cont++;
            }
            cb_proveedor.setModel(dcbm);
            cb_proveedor.setSelectedIndex(numcb);
             } catch (Exception ex) {
                Logger.getLogger(vistaTipoDeMaquina.class.getName()).log(Level.SEVERE, null, ex);
             }

                    bt_modificar.setEnabled(true);
                    bt_eliminar.setEnabled(true);
                    bt_agregar.setEnabled(false);
                    tx_buscar.setText("");
                } else{
                    JOptionPane.showMessageDialog(null,"Cliente no encontrado.");
                }
            }
            }
            catch (SQLException ex) {
                Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
            }
}

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.autocomplete.AutoCompleteDecorator autoCompleteDecorator1;
    private javax.swing.JButton bt_aceptarEliminar;
    private javax.swing.JButton bt_agregar;
    private javax.swing.JButton bt_buscar;
    private javax.swing.JButton bt_cancelarEliminar;
    private javax.swing.JButton bt_eliminar;
    private javax.swing.JButton bt_limpiar;
    private javax.swing.JButton bt_modificar;
    private javax.swing.JComboBox cb_proveedor;
    private javax.swing.JDialog dialogo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    private jcMousePanel.jcMousePanel jcMousePanel2;
    private jcMousePanel.jcMousePanel jcMousePanel3;
    private jcMousePanel.jcMousePanel jcMousePanel4;
    public static jcMousePanel.jcMousePanel pisoTipoDeMaquina;
    private javax.swing.JTable tablaMaquinas;
    private javax.swing.JTextField tx_buscar;
    private javax.swing.JTextField tx_codigo;
    private javax.swing.JTextField tx_millarNum;
    private javax.swing.JTextField tx_nombre;
    private javax.swing.JTextField tx_tamMaximo;
    private javax.swing.JTextField tx_tamMinimo;
    private javax.swing.JTextField tx_vrMillar;
    private javax.swing.JTextField tx_vrPlancha;
    // End of variables declaration//GEN-END:variables

}
